//
//  PatientTabViewController.m
//  Seizure
//
//  Created by student on 2/9/12.
//
//  The Patient View containing all the tabs

#import "PatientTabViewController.h"
#import "MotionDetectionViewController.h"
#import "SettingsTabViewController.h"
#import "VisualDetectionViewController.h"
#import "DataManager.h"

@implementation PatientTabViewController

@synthesize motionDetection;
@synthesize settings;
@synthesize visualDetection;
@synthesize currentController;
BOOL buttonsDisabled = NO;

// intialize PatientTabView Controller
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        MotionDetectionViewController *mdvControl = [[MotionDetectionViewController alloc] initWithNibName:@"MotionDetectionViewController" bundle:nil];
        [mdvControl setParent:self];
        SettingsTabViewController *stvControl = [[SettingsTabViewController alloc] initWithNibName:@"SettingsTabViewController" bundle:nil];
//        VisualDetectionViewController *vdvControl = [[VisualDetectionViewController alloc] initWithNibName:@"VisualDetectionViewController" bundle:nil];
        
        NSArray *controllers = [[NSArray alloc] initWithObjects:mdvControl, stvControl, nil];
        [self setViewControllers:controllers animated:YES];
        
        self.selectedViewController = mdvControl;
        [self setDelegate:self];
    }
    return self;
}

// disable the tab bar (for when detection is running)
-(void) disableTabBar:(BOOL)disabled {
    buttonsDisabled = disabled;
}

// disallow selecting a tab if the buttons are disabled
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    return !buttonsDisabled;
}
    

#pragma mark - View lifecycle

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)userLoggedOut
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

@end
